﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

public class InventoryScript : MonoBehaviour {
    public Transform inventoryPanel;

	void Start () {
        PlayerInventory.Add(SingletonManager.GenerateLootList(30));
        List<CraftMaterialAmount> sorted = PlayerInventory.inventory.OrderByDescending(o => o.material.rarity).ToList();

        foreach (CraftMaterialAmount cma in sorted)
        {
            Transform content = GameObject.Find("Content").transform;
            Transform created = Instantiate(inventoryPanel, content);
            created.GetChild(0).GetComponent<Image>().sprite = SingletonManager.GetSprite(cma.material);
            created.GetChild(0).GetComponent<Image>().preserveAspect = true;
            created.GetChild(1).GetComponent<Text>().text = cma.material.name;
            created.GetChild(2).GetComponent<Text>().text = cma.amount.ToString();
        }
	}
	
}
